unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, frxClass, frxDesgn, StdCtrls, frxDBSet, DB, DBClient, frxPreview,
  RepPrint;

type
  TFormMain = class(TForm)
    ClientDataSet1: TClientDataSet;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
    FRepPrint : TRepPrint;
    FRepData : OleVariant;
  public
    { Public declarations }
  end;

var
  FormMain: TFormMain;

implementation

{$R *.dfm}

procedure TFormMain.FormCreate(Sender: TObject);
begin
  FRepPrint := TRepPrint.Create(Self);

  with ClientDataSet1 do
  begin
    if Active then Close;
    FieldDefs.Clear;
    FieldDefs.Add('BM',ftString,10);
    FieldDefs.Add('MC',ftString,20);
    CreateDataSet;

    Append;
    FieldByName('BM').AsString := '001';
    FieldByName('MC').AsString := '001MC';
    Post;
    Append;
    FieldByName('BM').AsString := '002';
    FieldByName('MC').AsString := '002MC';
    Post;
  end;
end;

procedure TFormMain.Button3Click(Sender: TObject);
begin
  FRepPrint.DesignRep(FRepData);
end;

procedure TFormMain.FormDestroy(Sender: TObject);
begin
  FRepPrint.Free;
end;

procedure TFormMain.Button4Click(Sender: TObject);
begin
  FRepPrint.Initialize;
  FRepPrint.GetRepFormat(FRepData);
  FRepPrint.SetMasterDataSet(ClientDataSet1.Data);
  FRepPrint.SetDetailDataSet(ClientDataSet1.Data);

  FRepPrint.Preview;
end;

end.
